home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 832 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: pwolf-mac.qualcomm.com!user
  2. From: pwolf@qualcomm.com (Paul I. Wolf )
  3. Newsgroups: comp.lang.c
  4. Subject: Re: warning: possibly incorrect assignment
  5. Date: 9 Jan 1996 17:20:39 GMT
  6. Organization: Qualcomm, Inc.
  7. Message-ID: <pwolf-0901960920380001@pwolf-mac.qualcomm.com>
  8. References: <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>
  9. NNTP-Posting-Host: pwolf-mac.qualcomm.com
  10.  
  11. Your compiler is conservatively trying to warn you that you may be
  12. assigning instead of comparing FILE* objects with "==".
  13.  
  14. You may be able to use an extra pair of parentheses to suppress the warning
  15.    "while((fp=fopen(file_name,"r")))", but it depends on your compiler.
  16. Otherwise, you must separate the assignment and comparison statements to
  17. prevent being warned
  18.  
  19. In article <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>, Bill
  20. Simpson <wsimpson@uwinnipeg.ca> wrote:
  21.  
  22. > I get the above warning when I compile code using the following
  23. > function.  It flags the **** line.
  24. > void save_data(unsigned long int time[],int n)
  25. >         {
  26. >         char file_name[30];
  27. >         double t;
  28. >         int i;
  29. >         FILE * fp;
  30. >         printf("Enter file name: ");
  31. >         scanf("%s", file_name);
  32. > ****        while(fp=fopen(file_name,"r"))
  33. >                 {
  34. >                 printf("this file already exists--use another name\n");
  35. >                 fclose(fp);
  36. >                 printf("Enter filename:\n");
  37. >                 scanf("%s", file_name);
  38. >                 }
  39. >         fp=fopen(file_name,"w"); 
  40. >         for (i=0;i<n;i++)
  41. >                 {
  42. >                 t=(double)time[i]/1000000; /*convert from microsec to sec*/
  43. >                 fprintf(fp,"%.6f\n",t);
  44. >                 }
  45. >         fclose(fp);                         
  46. >                                        
  47. >         return;
  48. >         }
  49. > How can I write this code so the compiler does not issue this warning?
  50. > Please don't suggest I just tell the compiler to shut up.  In general
  51. > the warnings are useful.  I do not want to just ignore the warning either.
  52. > I have the FAQ and haven't seen this discussed.
  53. > (Any other improvements to above code segment welcomed)
  54. > Thanks very much for any help.
  55. > Bill Simpson
  56.